package com.wxtbk.controller.front;


import java.util.Date;
import java.util.List;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.wxtbk.model.WtWxuserOrder;


public class OrderController extends Controller{
	@ActionKey("/order")
	public void index() {
		
		String openId = getSessionAttr("openId");
		
		String type = getPara("m");
		if ( type.equals("new")){
			render("order.jsp");
			return;
		}
		List<WtWxuserOrder> orders = null;
		if(type.equals("all")){
			orders = WtWxuserOrder.dao.findByOpenid(openId, null);
						
		}else if ( type.equals("toret")){
			orders = WtWxuserOrder.dao.findByOpenid(openId, "N");
			
		}else if ( type.equals("ret")){
			orders = WtWxuserOrder.dao.findByOpenid(openId, "Y");
		}
		setAttr("orders",orders);
			
		render("orderlist.jsp");
	}
	@ActionKey("/order/add")
	public void doAddOrder(){
		String openId = getSessionAttr("openId");
		String orderno = getPara("orderno");
		
		if ( !WtWxuserOrder.dao.isExists(openId, orderno) ){ 
			WtWxuserOrder order = new WtWxuserOrder();
			order.setOpenId(openId);
			order.setOrderno(orderno);
			order.setStatus("N");
			order.setCreateTime(new Date());
			order.save();			
		}
		setAttr("statusCode",200);
		renderJson();
				
	}
}
